package com.scau.beyondboy.criminalintent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
public abstract class SingleFragmentActivity extends FragmentActivity
{
    private static final String TAG ="SingleFragmentActivity" ;
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_crime, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings)
        {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    /**初始化*/
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        Log.i(TAG, "onCreate");
        setContentView(R.layout.activity_fragment);
        super.onCreate(savedInstanceState);
        FragmentManager manager=getSupportFragmentManager();
        Fragment fragment=manager.findFragmentById(R.id.fragmentContainer);
        if(fragment==null)
        {
            fragment=creteFragment();
            manager.beginTransaction().add(R.id.fragmentContainer,fragment).commit();
        }
    }
    /**创建Fragment对象的模板方法*/
    protected abstract Fragment creteFragment();
}
